// pages/productDetailsTwo/index.js
const app = getApp();
var config = require('../../config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: config.imgPath,
    proInfo:{}
  },

  addFavorite:function () {
    let self = this
    app.request({
      url: 'api/UserCenter/addFavorite',
      method: "GET",
      data:{productId:self.data.proInfo.Id},
      success: function (res) {
        self.setData({
          isfavoter:true
        })
      }
    })
  },
  deleteFavorite:function (e) {
    var productId = this.data.proInfo.Id
    let self = this
    app.request({
      url: 'api/UserCenter/deleteFavorite',
      method: "GET",
      data:{productId:productId},
      success: function (res) {
        self.setData({
          isfavoter:false
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.editTabbar();
    this.loadInfo(options.id)
  },

  loadInfo(id) {
    let self = this
    app.request({
      url: 'api/product/getProductById',
      method: "GET",
      data:{id:id},
      success: function (res) {
        if (res.data != null) {
          var pro = res.data.proinfo

          if(pro.Content != null){
          pro.Content = pro.Content.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content1 != null){
          pro.content1 = pro.content1.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content2 != null){
          pro.content2 = pro.content2.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content3 != null){
          pro.content3 = pro.content3.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content4 != null){
          pro.content4 = pro.content4.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content5 != null){
          pro.content5 = pro.content5.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content6 != null){
          pro.content6 = pro.content6.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content7 != null){
          pro.content7 = pro.content7.replace(/<img/g, '<img class="richImg"')
          }

          if(pro.content8 != null){
          pro.content8 = pro.content8.replace(/<img/g, '<img class="richImg"')
          }
            self.setData({
              proInfo: pro,
              isfavoter:res.data.isfavoter
            })
          }

          app.request({
            url: 'api/product/getaclist',
            method: "GET",
            data:{id:self.data.proInfo.Id,name:"企业资质"},
            success: function (res) {
              console.log(res)
              if (res.data != null) {
                  self.setData({
                    zizhiList:res.data.list
                  })
              }
            }
          })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})